package com.shujia.base;

import com.shujia.utils.MySQLTool;

import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Arrays;

public class LoadData {
    public static void main(String[] args) throws Exception {
        Connection conn = MySQLTool.getConnection();
        PreparedStatement preparedStatement = conn.prepareStatement("insert into jd_goods values(?,?,?,?,?,?)");

        BufferedReader br = new BufferedReader(new FileReader("D:\\projects\\IdeaProjects\\bigdata32\\redis\\src\\main\\resources\\jd_goods.csv"));

        int i = 1;
        String line = null;
        while ((line=br.readLine())!=null){
            if(line.endsWith(",")){
                line = line.concat("null");
            }

            String[] infos = line.split(",");
            System.out.println(Arrays.toString(infos));
            System.out.println(infos[4]);
            preparedStatement.setInt(1,i);
            preparedStatement.setString(2,infos[0]);
            preparedStatement.setString(3,infos[1]);
            preparedStatement.setString(4,infos[2]);
            preparedStatement.setString(5,infos[3]);
            preparedStatement.setString(6,infos[4]);

            preparedStatement.executeUpdate();
            i++;
        }



    }
}
